<template>
  <div class="app-container">
    <!--form 组件-->
    <eForm ref="form" :is-add="isAdd" :dicts="dicts"/>
    <el-row :gutter="20">
      <!--部门数据-->
      <el-col :xs="7" :sm="6" :md="4" :lg="4" :xl="4">
        <!-- <div class="head-container">
          <el-input v-model="deptName" clearable placeholder="输入部门名称搜索" prefix-icon="el-icon-search" style="width: 100%;" class="filter-item" @input="getDeptDatas"/>
        </div> -->
        <el-tree :data="depts" :props="defaultProps" :expand-on-click-node="false"  default-expand-all  node-key="id" :default-checked-keys="[4]"  ref="eltree"  @node-click="handleNodeClick"/>
		<!-- <el-tree :data="data" :props="defaultProps" @node-click="handleNodeClick"></el-tree> -->
      </el-col>
      <!--用户数据-->
      <el-col :xs="17" :sm="18" :md="20" :lg="20" :xl="20">
        <!--工具栏-->
        <!-- <div class="head-container">
          <el-input v-model="query.value" clearable placeholder="输入关键字搜索" style="width: 200px;" class="filter-item" @keyup.enter.native="toQuery"/>
          <el-select v-model="query.type" clearable placeholder="类型" class="filter-item" style="width: 130px">
            <el-option v-for="item in queryTypeOptions" :key="item.key" :label="item.display_name" :value="item.key"/>
          </el-select>
          <el-select v-model="query.enabled" clearable placeholder="状态" class="filter-item" style="width: 90px" @change="toQuery">
            <el-option v-for="item in enabledTypeOptions" :key="item.key" :label="item.display_name" :value="item.key"/>
          </el-select>
          <el-button class="filter-item" size="mini" type="success" icon="el-icon-search" @click="toQuery">搜索</el-button>
          <div v-permission="['ADMIN','USER_ALL','USER_CREATE']" style="display: inline-block;margin: 0px 2px;">
            <el-button
              class="filter-item"
              size="mini"
              type="primary"
              icon="el-icon-plus"
              @click="add">新增</el-button>
          </div>
          <div style="display: inline-block;">
            <el-button
              v-permission="['ADMIN']"
              :loading="downloadLoading"
              size="mini"
              class="filter-item"
              type="warning"
              icon="el-icon-download"
              @click="download">导出</el-button>
          </div>
        </div> -->

      <div class="head-container">
		<el-row style="display:flex;flex-direction:rows">
			<el-col :span="6">
				<span class="title">机构名称:</span>
				<el-input v-model="form.dept"  placeholder="输入机构名称" style="width: 200px;" class="filter-item" @keyup.enter.native="loanList"/>
			</el-col>
		

			<!-- 搜索 -->
			<!-- <el-input v-model="query.value" clearable placeholder="输入搜索内容" style="width: 200px;" class="filter-item" @keyup.enter.native="toQuery"/>
			<el-select v-model="query.type" clearable placeholder="类型" class="filter-item" style="width: 130px">
				<el-option v-for="item in queryTypeOptions" :key="item.key" :label="item.display_name" :value="item.key"/>
			</el-select> -->
			<el-button v-permission="['ADMIN','LOANCHECKTASK_ALL','LOANCHECKTASK_SELECT']" class="filter-item" size="mini" type="success" icon="el-icon-search" @click="loanList">搜索</el-button>
			<el-button  v-permission="['ADMIN','LOANCHECKTASK_ALL','LOANCHECKTASK_SELECT']" class="filter-item" size="mini" type="success" icon="el-icon-delete-solid" @click="resetSearch">清空</el-button>
			<el-button  v-permission="['ADMIN','LOANCHECKTASK_ALL','LOANCHECKTASK_CREAT']" class="filter-item" size="mini" type="success" icon="el-icon-plus" @click="newAdd">新增</el-button>
			<el-button v-permission="['ADMIN','LOANCHECKTASK_ALL','LOANCHECKTASK_REPORT_INFO']" class="filter-item" size="mini" type="success" icon="el-icon-view" @click="toDetails">报告详情</el-button>
			<el-button  v-permission="['ADMIN','LOANCHECKTASK_ALL','LOANCHECKTASK_SUBMIT']" class="filter-item" size="mini" type="success" icon="el-icon-finished" @click="submitProcess">提交</el-button>
			<!-- 新增 -->
			<!-- <div style="display: inline-block;margin: 0px 2px;">
				<el-button
				v-permission="['ADMIN','CUSTCOMBASEINFO_ALL','CUSTCOMBASEINFO_CREATE']"
				class="filter-item"
				size="mini"
				type="primary"
				icon="el-icon-plus"
				@click="add">新增</el-button>
			</div> -->
	   </el-row>
    </div>





        <!--表格渲染-->
		<el-table v-loading="loading" :data="data" size="small" style="width: 100%;"  @selection-change="handleSelectionChange">
			 <el-table-column type="selection" width="50"></el-table-column>	     
            <el-table-column prop="contractNo" label="合同流水号"/>
			<el-table-column prop="custName" label="客户名称"/>
			<!-- <el-table-column prop="busiType" label="业务品种"/> -->

            <el-table-column label="业务品种" align="center">
					<template slot-scope="scope">
					<div v-for="item in dictMap.busi_type" :key="item.id">
						<span v-if="scope.row.busiType == item.value">{{ item.label }}</span>
					</div>
					</template>
			</el-table-column>




			<el-table-column prop="happenType" label="发生类型"/>
			<el-table-column prop="currency" label="币种"/>
			<el-table-column prop="contractAmount" label="合同金额"/>
			<el-table-column prop="balance" label="余额"/>
			<el-table-column prop="overdueAmount" label="逾期/垫款金额"/>
			<el-table-column prop="principalFine" label="本金罚息金额"/>
			<el-table-column prop="interestFine" label="利息罚息金额"/>
			<el-table-column prop="yearRate" label="利率"/>
			<el-table-column :show-overflow-tooltip="true" prop="contractStart" label="起始日期">
				<template slot-scope="scope">
				<span>{{ parseTime(scope.row.contractStart) }}</span>
				</template>
            </el-table-column>
			<el-table-column :show-overflow-tooltip="true" prop="contractEnd" label="到期日期">
				<template slot-scope="scope">
				<span>{{ parseTime(scope.row.contractEnd) }}</span>
				</template>
            </el-table-column>
		    <el-table-column prop="guaranteeMode" label="担保方式"/>
			 <el-table-column label="状态" align="center">
					<template slot-scope="scope">
					<div v-for="item in dictMap.process_satus" :key="item.id">
						<span v-if="scope.row.status == item.value">{{ item.label }}</span>
					</div>
					</template>
			</el-table-column>
			<el-table-column prop="custManager" label="客户经理"/>
			<el-table-column prop="dept" label="机构"/>
		</el-table>
        <!--分页组件-->
        <el-pagination
          :total="total"
          :current-page="page + 1"
          style="margin-top: 8px;"
          layout="total, prev, pager, next, sizes"
          @size-change="sizeChange"
          @current-change="pageChange"/>
      </el-col>
    </el-row>



	<el-dialog :visible.sync="dialog" title="" append-to-body width="870px">
		  <el-table v-loading="loading" :data="taskData" size="small" style="width: 100%;" @selection-change="select">
			       <el-table-column type="selection" width="50"></el-table-column>
			       <el-table-column prop="contractNo" label="合同编号"/>
			       <el-table-column prop="custNum" label="客户编号"/>
			       <el-table-column prop="custName" label="客户名称"/>
				   <!-- <el-table-column prop="busiType" label="业务品种"/> -->

                    <el-table-column label="业务品种" align="center">
						<template slot-scope="scope">
						<div v-for="item in dictMap.busi_type" :key="item.id">
							<span v-if="scope.row.busiType == item.value">{{ item.label }}</span>
						</div>
						</template>
			        </el-table-column>

				   <el-table-column prop="contractAmount" label="合同金额"/>
		  </el-table>
		  <el-pagination
          :total="taskToal"
          :current-page="page + 1"
          style="margin-top: 8px;"
          layout="total, prev, pager, next, sizes"
          @size-change="sizeChangeTask"
          @current-change="pageChangeTask"/>
		<div slot="footer" class="dialog-footer" style="display:flex;justify-content:center">
			<el-button :loading="loading" type="primary" @click="selectTask">确认</el-button>
			<el-button type="text" @click="cancel">取消</el-button>
		</div>
	</el-dialog>



	<!-- <el-dialog :visible.sync="dialogProcess" title="提交流程" append-to-body width="870px">
        <el-tree
            ref="menu"
            :data="menus"
            :default-checked-keys="menuIds"
            :props="defaultProps1"
            accordion
            show-checkbox
            node-key="id"/>
        <div slot="footer" class="dialog-footer" style="display:flex;justify-content:center">
			<el-button :loading="loading" type="primary" @click="sureSubmitProcess">确认</el-button>
			<el-button type="text" @click="cancelProcess">取消</el-button>
		</div>
	</el-dialog> -->


	<el-dialog :visible.sync="dialogProcess" title="提交流程" append-to-body width="870px">
        <!-- <el-tree
            ref="menu"
            :data="menus"
            :default-checked-keys="menuIds"
            :props="defaultProps1"
            accordion
            show-checkbox
            node-key="id"/> -->
			<el-tabs tab-position="left" >
				<el-tab-pane  :label="item.label" v-for="(item,k) in fatherLabel" :key="k">
					 <el-table
								:data="item.children"
								style="width: 100%"
								ref="tableForm">
								<el-table-column
									type="selection"
									width="55">
								</el-table-column>
								<el-table-column
										prop="id"
										label="id"
										>
								</el-table-column>
								<el-table-column
										prop="pid"
										label="pid"
										>
								</el-table-column>
								<el-table-column
										prop="label"
										label="label"
										>
								</el-table-column>
							
							</el-table>
						<div  class="dialog-footer" style="display:flex;justify-content:center;margin-top:20px">
							<el-button :loading="loading" type="primary" @click="sureSubmitProcess(k)">确认</el-button>
							<el-button type="text" @click="cancelProcess">取消</el-button>
						</div>
				</el-tab-pane>
			</el-tabs>
        
	</el-dialog>
  </div>
</template>

<script>
import checkPermission from '@/utils/permission'

import { loanList ,check ,task,  selectTask ,processTree , subProcessId ,busiProcess , processTreeLoanList ,getProcessDefinitionId} from '@/api/loanManageInfo'
import { processLoanTreeList} from '@/api/assetClassificationInfo'

import { getPermissionTree,subTree } from '@/api/permission'
import { getMenusTree } from '@/api/menu'

import initData from '@/mixins/initData'
import initDict from '@/mixins/initDict'
import { del } from '@/api/user'
import { getDepts } from '@/api/dept'
import { parseTime } from '@/utils/index'
import eForm from './form'
export default {
  components: { eForm },
  mixins: [initData, initDict],
  data() {
    return {
      height: document.documentElement.clientHeight - 180 + 'px;', isAdd: false,
      delLoading: false, deptName: '', depts: [], deptId: null,
      defaultProps: {
        children: 'children',
        label: 'name'
      },
      downloadLoading: false,
      queryTypeOptions: [
        { key: 'username', display_name: '用户名' },
        { key: 'email', display_name: '邮箱' }
      ],
      enabledTypeOptions: [
        { key: 'true', display_name: '激活' },
        { key: 'false', display_name: '锁定' }
	  ],

    


	  lastStyle:null,
      form:{
		page: 0, 
		size: 10,
		sort:'id,desc',
		dept:'',
		types:null,
	  },
	  current:{
		 page: 0, 
		 size: 10,
	 	 sort:'id,desc', 
	  },
	  ids:[],
	  id:'',
	  temIds:[],
	  
	  busiFlag:'CONST_LOAN_AFTER',
	  processDefinitionId:'',
	  name:'',




	  fatherLabel:[],
	  dialog:false,
	  dialogProcess:false,
	  taskData:[],
	  taskToal:null,
	  formm:{
		page: 0, 
		size: 10,
		sort:'id,desc'
	  },
	  idsTask:[],
	  idTask:'',
	  busiTypes:[],
	  busiType:'',
	  custKinds:[],
	  custKind:'',
	  constractNos:[],
	  constractNo:'',

	  forms:{
		 contractNo:'' 
	  },

	  content:[
		  {
			  id:'1',
			  types:null,
			  name:'贷后检查',
			  pid:'0',
			  children:[{
				  id:'2',
                  types:null,
				  name:'未完成贷后检查',
				  pid:'0',
				  children:[
					  {id:'4',types:'unfinished-first',name:'首次贷后检查',pid:'1'},
					  {id:'5',types:'unfinished-common',name:'常规贷后检查',pid:'1'},
					  {id:'6',types:'unfinished-major',name:'专项贷后检查',pid:'1'}
				  ]
			   },
			   {
				  id:'3', 
                  types:null,
				  name:'已完成贷后检查',
				  pid:'0',
                  children:[
					  {id:'7',types:'finished-first',name:'首次贷后检查',pid:'1'},
					  {id:'8',types:'finished-common',name:'常规贷后检查',pid:'1'},
					  {id:'9',types:'finished-major',name:'专项贷后检查',pid:'1'}
				  ]
			   }
			 ]
		  }
	  ],

	  permissions: [], permissionIds: [], menus: [], menuIds: [],
	  defaultProps1: {
        children: 'children',
        label: 'label'
      },
    }
  },
  created() {
   // this.loanList()

    this.getDeptDatas()
     this.$nextTick(() => {
		this.getDictMap('process_satus,busi_type')
		 this.loanList()
		 this.getProcessDefinitionId()
    //   this.init()
    //   // 加载数据字典
    //   this.getDict('user_status')
     })
  },
  mounted: function() {
	  console.log('====',this.$refs.eltree)
	console.log('---',this.$refs.eltree.$el.children[0])
	// console.log('------',document.getElementsByTagName('span'))
	// const list = document.getElementsByTagName('span');
	// for(var i=0;i<=list.length;i++){
	// 	if(list[i].innerHTML =='表内业务'){
    //          list[i].style.color = 'red'
	// 	}	
	// }
	// if(document.getElementsByClassName('span')[0].outerHTML =='表内业务'){
	// 	document.getElementsByClassName('span')[0].style.color = 'red'
	// }
    const that = this
    window.onresize = function temp() {
      that.height = document.documentElement.clientHeight - 180 + 'px;'
    }
  },
  methods: {
    parseTime,
    checkPermission,
    beforeInit() {
      this.url = 'api/loanManage/loanBackCheck/tasks'
      const sort = 'id,desc'
      const query = this.query
      const type = query.type
      const value = query.value
      const enabled = query.enabled
      this.params = { page: this.page, size: this.size, sort: sort, dept:this.form.dept,types: this.form.types }
      if (type && value) { this.params[type] = value }
      if (enabled !== '' && enabled !== null) { this.params['enabled'] = enabled }
      return true
	},
	getProcessDefinitionId(){
		getProcessDefinitionId(this.busiFlag).then(res => {
			this.processDefinitionId = res.pInstId
			this.name = res.pName
		}).catch(err => {
            this.loading = false
            console.log(err.response.data.message)
        })
	},
	loanList(){
		console.log('this.form',this.form)
		  check(this.form).then(res => {
            this.total = res.totalElements
			this.data = res.content
			setTimeout(() => {
                this.loading = false
             }, 170)
          }).catch(err => {
            this.loading = false
            console.log(err.response.data.message)
          })
	},
	resetSearch(){
		   this.form.dept = '';
		   this.loanList()
		   setTimeout(() => {
                this.loading = false
           }, 170)
	},
	submitProcess(){
         if(this.id == ''){
		     this.$message.warning('请先选择某一项！')
		      return;
		  }
		  console.log('yyyyyy',this.id.split(','))
		  if(this.id.split(',').length>=2){
				this.$message.warning('只能选择一项！')
				return;
		  }

         sessionStorage.setItem('busiId',this.id)

		// processTree().then(res => {
		// 	console.log(res)
		// 	this.fatherLabel= res
		// })


        processTreeLoanList(this.processDefinitionId).then(res => {
			console.log(res)
			if(res.code == '0'){
                this.fatherLabel= res.data
			}	
			//this.fatherLabel= res
		})



		// subTree().then(res => {
		// 	console.log(res)
		// 	this.fatherLabel= res
		// })
		 this.dialogProcess = true;
		//  this.getPermissions()
		//  this.getMenus()
		 
	},
	getPermissions() {
      getPermissionTree().then(res => {
        this.permissions = res
      })
    },
    getMenus() {
      getMenusTree().then(res => {
		this.menus = res
		console.log('tree',res)
      })
	},
	cancelProcess(){
		this.dialogProcess = false;
	},
	sureSubmitProcess(k){
		console.log(this.$refs.tableForm[k])
		let selectData = this.$refs.tableForm[k].selection
		console.log(selectData)
		if(selectData.length!=1){
			  this.$message({
				message: '请选择一条数据',
				type: 'warning'
				});
				return
		}
		console.log('uuuu',selectData)
		// 下面提交接口
         const para = {
			  claimUserId:selectData[0].id,
			  name:this.name,
			  processDefinitionId:this.processDefinitionId
			 // name:'贷后检查报告审批流程',
			  //processDefinitionId:'report_check_process:2:06677af6-17d1-11ea-8c68-c0a5dda0ba60'
			 // processDefinitionId:'test_loan_after_process:1:5c69e2ec-2788-11ea-b64b-c0a5dda0ba60'
		 }
		//subProcessId(selectData[0].id).then(res => {
        subProcessId(para).then(res => {
               const par ={
				   busiId:sessionStorage.getItem('busiId'),
				   instanceId:res.id
			   }

               busiProcess(par).then(res => {
				   this.$message.success('提交流程成功！')
				    this.loanList()
                    this.dialogProcess = false
               }).catch(err => {
                      console.log(err.response.data.message)
			   })
		})
	},
	newAdd(){
		this.dialog = true
		console.log('this.formm',this.formm)
		task(this.formm).then(res => {
           // this.total = res.totalElements
			//this.data = res.content
			this.taskData = res.content
			this.taskToal = res.totalElements
			setTimeout(() => {
                this.loading = false
             }, 170)
        }).catch(err => {
            this.loading = false
            console.log(err.response.data.message)
        })
	},
	pageChangeTask(current){
		console.log('current-1',current-1)
		this.formm.page = current-1;

		task(this.formm).then(res => {
          //  this.total = res.totalElements
		//	this.data = res.content
			this.taskData = res.content
			this.taskToal = res.totalElements
			setTimeout(() => {
                this.loading = false
             }, 170)
        }).catch(err => {
            this.loading = false
            console.log(err.response.data.message)
        })

	},
	sizeChangeTask(size){
		console.log('size',size)
		this.formm.size = size;

		task(this.formm).then(res => {
           // this.total = res.totalElements
			//this.data = res.content
			this.taskData = res.content
			this.taskToal = res.totalElements
			setTimeout(() => {
                this.loading = false
             }, 170)
        }).catch(err => {
            this.loading = false
            console.log(err.response.data.message)
        })
	},
	cancel(){
		this.dialog = false
		this.idTask = ''
		this.busiType = ''
		this.custKind = ''
	},
	//  handleSelectionChange(val) {
	// 	  console.log('val',val)
	// 	   val.forEach((v) => {
    //            this.ids.push(v.id)
	// 	   });
	// 	   console.log('ids',this.ids)
	// 	   this.id = this.ids.toString()
	// 	   this.ids = []
	// 	   console.log('this.id',this.id)
	// },
	handleSelectionChange(val) {
		  console.log('val',val)
		   val.forEach((v) => {
               this.ids.push(v.id)
		   });
		   console.log('ids',this.ids)
		   this.temIds = this.Ids
		   this.id = this.ids.toString()
		   this.ids = []
		   console.log('this.id',this.id)
	},
	toDetails(){
		   if(this.id == ''){
			  this.$message.warning('请选择某一项！')
			  return;
		   }else if(this.id.split(',').length != '1'){
			  this.$message.warning('只能选择某一任务！')
			  return;
		   }
		   sessionStorage.setItem('editReportId',this.id)
		   this.$router.push({ name: "reportTemplateDetails", params: { editReportId :this.id} })  
		  // console.log('id',this.$route.params.id)
	},
	// select(val){
    //        console.log('val',val)
	// 	   val.forEach((v) => {
    //            this.idsTask.push(v.id)
	// 	   });
	// 	   console.log('idsTask',this.idsTask)
	// 	   this.idTask = this.idsTask.toString()
	// 	   this.idsTask = []
	// 	   console.log('this.idTask',this.idTask)
	// },
	select(val){
           console.log('val',val)
		   val.forEach((v) => {
			   this.idsTask.push(v.id)
			   this.busiTypes.push(v.busiType)
			   this.custKinds.push(v.custKind)
			   this.constractNos.push(v.contractNo)
		   });
		   console.log('idsTask',this.idsTask)
		   this.idTask = this.idsTask.toString()
		   this.busiType = this.busiTypes.toString()
		   this.custKind = this.custKinds.toString()
		   this.constractNo = this.constractNos.toString()
		   this.idsTask = []
		   this.busiTypes = []
		   this.custKinds = []
		   this.constractNos = []
		   console.log('this.idTask',this.idTask)
		   console.log('this.busiType',this.busiType)
		   console.log('this.custKind',this.custKind)
		
	},
	// selectTask(){
	// 	   //alert(1)
	// 	   console.log('this.idTask',this.idTask.split(',').length)
	// 	   console.log('this.busiType',this.busiType.split(',').length)
	// 	   console.log('this.custKind',this.custKind.split(',').length)

	// 	   console.log('this.idTask---',this.idTask)
	// 	   console.log('this.busiType---',this.busiType)
	// 	   console.log('this.custKind---',this.custKind)
		   
	// 	   if(this.idTask == ''){
	// 		  this.$message.warning('请选择某一任务！')
	// 		  return;
	// 	   }else if(this.idTask.split(',').length != '1' && this.busiType.split(',').length != '1' && this.custKind.split(',').length != '1'){
	// 		  this.$message.warning('只能选择某一任务！')
	// 		  return;
	// 	   }
	// 	   sessionStorage.setItem('idTask',this.idTask)
	// 	   sessionStorage.setItem('busiTypeTask',this.busiType)
	// 	   sessionStorage.setItem('custKindTask',this.custKind)

	// 	   this.$router.push({ name: "reportTemplates"})  
	// },
    selectTask(){
		   //alert(1)
		   console.log('this.idTask',this.idTask.split(',').length)
		   console.log('this.busiType',this.busiType.split(',').length)
		   console.log('this.custKind',this.custKind.split(',').length)

		   console.log('this.idTask---',this.idTask)
		   console.log('this.busiType---',this.busiType)
		   console.log('this.custKind---',this.custKind)
		   console.log('this.constractNo---',this.constractNo)
		   if(this.constractNo == ''){
			  this.$message.warning('请选择某一任务！')
			  return;
		   }else if(this.constractNo.split(',').length != '1'){
			  this.$message.warning('只能选择某一任务！')
			  return;
		   }
		   sessionStorage.setItem('idTask',this.idTask)
		   sessionStorage.setItem('busiTypeTask',this.busiType)
		   sessionStorage.setItem('custKindTask',this.custKind)
		   sessionStorage.setItem('constractNoTask',this.constractNo)
		   
		   this.forms.contractNo = this.constractNo
		  		selectTask(this.forms).then(res => {
					    this.dialog = false
						console.log('res====',res.id)
						sessionStorage.setItem('itemId',res.id)
						this.$router.push({ name: "reportTemplates"})  
						setTimeout(() => {
							this.loading = false
						}, 170)
				}).catch(err => {
				     this.loading = false
			
			    })


		  // this.$router.push({ name: "reportTemplates"})  
	},


    subDelete(id) {
      this.delLoading = true
      del(id).then(res => {
        this.delLoading = false
        this.$refs[id].doClose()
        this.dleChangePage()
        this.init()
        this.$notify({
          title: '删除成功',
          type: 'success',
          duration: 2500
        })
      }).catch(err => {
        this.delLoading = false
        this.$refs[id].doClose()
        console.log(err.response.data.message)
      })
    },
    getDeptDatas() {
      const sort = 'id,desc'
      const params = { sort: sort }
      if (this.deptName) { params['name'] = this.deptName }
      getDepts(params).then(res => {
	    //this.depts = res.content
	   this.depts = this.content
      })
    },
    // handleNodeClick(data,node,el) {
	// 	// if(this.lastStyle!=null){
	// 	// 	this.lastStyle.$el.style.color = "black"
	// 	// }
	// 	// if(data.type!=1){
	// 	// 	el.$el.style.color="red"
	// 	// }
	// 	// this.lastStyle = el
	// 	// console.log('el',el)
	// 	// console.log(node,el)
	// 	console.log('data',data)
    //   if (data.pid === 0) {
    //     this.deptId = null
    //   } else {
    //     this.deptId = data.id
    //   }
    //   this.init()
	// },

	  handleNodeClick(data,node,el) {
		// if(this.lastStyle!=null){
		// 	this.lastStyle.$el.style.color = "black"
		// }
		// if(data.type!=1){
		// 	el.$el.style.color="red"
		// }
		// this.lastStyle = el
		// console.log('el',el)
		// console.log(node,el)
		console.log('data',data)
      if (data.pid === 0) {
        this.form.types = null
      } else {
        this.form.types = data.types
      }
      this.loanList()
	},
	
    add() {
      this.isAdd = true
      this.$refs.form.getDepts()
      this.$refs.form.getRoles()
      this.$refs.form.getRoleLevel()
      this.$refs.form.dialog = true
    },
    // 导出
    download() {
      this.downloadLoading = true
      import('@/utils/export2Excel').then(excel => {
        const tHeader = ['ID', '用户名', '邮箱', '头像地址', '状态', '注册日期', '最后修改密码日期']
        const filterVal = ['id', 'username', 'email', 'avatar', 'enabled', 'createTime', 'lastPasswordResetTime']
        const data = this.formatJson(filterVal, this.data)
        excel.export_json_to_excel({
          header: tHeader,
          data,
          filename: 'table-list'
        })
        this.downloadLoading = false
      })
    },
    // 数据转换
    formatJson(filterVal, jsonData) {
      return jsonData.map(v => filterVal.map(j => {
        if (j === 'createTime' || j === 'lastPasswordResetTime') {
          return parseTime(v[j])
        } else if (j === 'enabled') {
          return parseTime(v[j]) ? '启用' : '禁用'
        } else {
          return v[j]
        }
      }))
    },
    edit(data) {
      this.isAdd = false
      const _this = this.$refs.form
      _this.getRoles()
      _this.getDepts()
      _this.getRoleLevel()
      _this.roleIds = []
      _this.form = { id: data.id, username: data.username, phone: data.phone, email: data.email, enabled: data.enabled.toString(), roles: [], dept: { id: data.dept.id }, job: { id: data.job.id }}
      data.roles.forEach(function(data, index) {
        _this.roleIds.push(data.id)
      })
      _this.deptId = data.dept.id
      _this.jobId = data.job.id
      _this.getJobs(_this.deptId)
      _this.dialog = true
    }
  }
}
</script>

<style scoped>
</style>
